#include <stdio.h>
#include <stdlib.h>

int main() {
    int N;
    scanf("%d", &N); 

    int c[1001] = {0}; 
    int a, b;
    
    for (int i = 0; i < N; i++) {
        char d[10];  
        int e;
        scanf("%s %d", d, &b);  

        sscanf(d, "%d-%d", &a, &e);  

        c[a] += b;
    }

    int f = 0, g = 0;
    for (int i = 1; i <= 1000; i++) {
        if (c[i] > g) {
            g = c[i];
            f = i;
        }
    }

    printf("%d %d\n", f, g);
    
    return 0;
}
